//
//  ViewController.m
//  UIHomeWork10 - 易车
//
//  Created by tusm on 16/7/27.
//  Copyright © 2016年 tusm. All rights reserved.
//

#import "ViewController.h"
#import "ModelOfTitleCell.h"
#import "TitleTableViewCell.h"
#import "JHButton.h"
#define kBttonWidth (self.view.frame.size.width / 4 - 40)
#define kClearanceWithEdge 20
#define kClearanceWithButton 40
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong )NSMutableArray *objectArray;
@property (nonatomic,strong)UIScrollView * scrollHeadView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view, typically from a nib.
    _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
    [_tableView registerClass:[TitleTableViewCell class] forCellReuseIdentifier:@"pool"];
    
        [self handledata];
    [self createHeadView];
}

- (void)createHeadView{
    
    //背景View
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 350)];
    view.backgroundColor = [UIColor yellowColor];
    _tableView.tableHeaderView = view;
    //scroller
    self.scrollHeadView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 250)];
    _scrollHeadView.contentSize = CGSizeMake(self.view.frame.size.width * 5, 250);
    _scrollHeadView.pagingEnabled = YES;
    _scrollHeadView.backgroundColor = [UIColor redColor];
    [view addSubview:_scrollHeadView];
    //四个button
    JHButton *leftBtn1 = [JHButton buttonWithType:UIButtonTypeCustom frame:CGRectMake(kClearanceWithEdge, 260, kBttonWidth, 80) title:@"贷款买车" titleColor:[UIColor blackColor] titleFont:15 textAlignment:NSTextAlignmentCenter image:[UIImage imageNamed:@"1"] imageViewContentMode:UIViewContentModeScaleToFill handler:^(UIButton *sender) {
        
    }];
    [view addSubview:leftBtn1];
    
    JHButton *leftBtn2 = [JHButton buttonWithType:UIButtonTypeCustom frame:CGRectMake(kClearanceWithEdge + kBttonWidth + kClearanceWithButton, 260,kBttonWidth , 80) title:@"直销车型" titleColor:[UIColor blackColor] titleFont:15 textAlignment:NSTextAlignmentCenter image:[UIImage imageNamed:@"2"] imageViewContentMode:UIViewContentModeScaleToFill handler:^(UIButton *sender) {
        
    }];
    [view addSubview:leftBtn2];
    
    JHButton *leftBtn3 = [JHButton buttonWithType:UIButtonTypeCustom frame:CGRectMake(kClearanceWithEdge + kBttonWidth * 2 + kClearanceWithButton *2, 260,kBttonWidth , 80) title:@"低价买车" titleColor:[UIColor blackColor] titleFont:15 textAlignment:NSTextAlignmentCenter image:[UIImage imageNamed:@"3"] imageViewContentMode:UIViewContentModeScaleToFill handler:^(UIButton *sender) {
        
    }];
    [view addSubview:leftBtn3];
    
    JHButton *leftBtn4 = [JHButton buttonWithType:UIButtonTypeCustom frame:CGRectMake(kClearanceWithEdge + kBttonWidth * 3 + kClearanceWithButton *3, 260,kBttonWidth , 80) title:@"二手车" titleColor:[UIColor blackColor] titleFont:15 textAlignment:NSTextAlignmentCenter image:[UIImage imageNamed:@"4"] imageViewContentMode:UIViewContentModeScaleToFill handler:^(UIButton *sender) {
        
    }];
    [view addSubview:leftBtn4];
    
    
    


}


- (void)handledata{
    ModelOfTitleCell *newObject = [[ModelOfTitleCell alloc] initWithLabelStr:@"fsljfeoiiii" imageStr:@"1"];

    _objectArray = [NSMutableArray array];
    for (int i = 0; i < 100; i ++) {
        [_objectArray addObject:newObject];
    }

}




- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{


    return _objectArray.count;

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    TitleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pool"];
    cell.modelOfTitleCell = self.objectArray[indexPath.row];
    return cell;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{


    return 100;

}









- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
